#include "PainterEngine_Application.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <windows.h>
#include <time.h>
#include "map.h"
#include "mine_map.h"
#include "opt.h"
#include "sort.h"

PX_Application App;

PX_Object *root = PX_NULL;	   //定义根类型 （px必须）
PX_Object *cellbutton[40][40]; //定义了十个小格子的按钮

px_texture titlepicture;	  //标题的图片（在welcome里面
px_texture potatoboompicture; //标题的图片（在welcome里面

px_texture firstprizepicture;  //第一的图片（in rank
px_texture secondprizepicture; //第2的图片（in rank
px_texture thirdprizepicture;
px_texture rank4pic;
px_texture rank5pic;
px_texture rank6pic;
px_texture ranktitlepicture; //排行版的图片（in rank

PX_Object *failpic;
PX_Object *recordname_message;
px_texture failpicture; //失败的图片与图片框
px_texture cheerpicture;
px_texture modechoose_title_picture;
px_texture modechoose_check;
px_texture help_title_picture;
px_texture help_text_picture;
px_texture what_is_this_pic;
px_texture ranknote2pic;
px_texture compass;
px_texture modechoose_rank_title_picture;
px_texture modechoose_rank_trophypic;
px_texture modechoose_rank_notepic;

px_texture easyrankpic;
px_texture midrankpic;
px_texture hardrankpic;
px_texture dividline;
px_texture waiting_fordata;

px_shape flag;
px_shape flag2;
px_shape flag3; //旗帜的图片（in game
px_shape mine;
px_shape mine2;
px_shape mine3; //雷的图片（in game 	数字代表对应困难度下的图片形式，如2代表中等难度

opt_t cell[100][100];
map *Map = NULL;
int mode = 1;
int RANKmode = 1;
int colormode = 0;
clock_t start, stop;
float duration; // 经历的时间
px_char *NAME;
char name1[50] = "NULL";
//////////////////////////////函数声明/////////////////////////////////
void WELCOME();
void RANK();
void Gameinit();
void Gamefail();
void Gamenow();
void Lclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void Rclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void Mclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
px_void *towelcomeclick(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void restart(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
px_void *towelcomeclick2(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void openall(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void openhelp(px_void *userptr);
void save_to_file(px_void *userptr);
px_void *congratulation(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
px_void *congratulation2(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
px_void *recordnameY(PX_Object *pObject, PX_Object_Event e, px_void *ptr);
void setcol_white(px_void *userptr);
void setcol_pink(px_void *userptr);
void setcol_purple(px_void *userptr);
void setcol_green(px_void *userptr);
void opencolorfulegg(px_void *userptr);

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////

//游戏正在进行的组件

void Gameinit()
{
	//重新创建根对象
	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);
	///变换界面就删除原页面的object！（由Painterengine provide)///

	//初始化map
	Map = CreateMap(mode);
	//生成cellbutton
	int buttonlong, buttonmovedown;
	switch (mode)
	{
	case MODE_EASY:
		buttonlong = 50;
		buttonmovedown = 0;
		break;
	case MODE_MID:
		buttonlong = 31;
		buttonmovedown = 0;
		break;
	case MODE_HARD:
		buttonlong = 24;
		buttonmovedown = 50;
		break;
	} //根据大小生成buttoncell，buttonlong代表button的宽度，buttonmovedone是对困难模式时按钮向下移动
	for (int i = 1; i <= Map->my; i++)
	{
		for (int j = 1; j <= Map->mx; j++)
		{
			cell[j][i].y = i;
			cell[j][i].x = j; // j行i列 x行y
			cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 1 + i * buttonlong - buttonlong, 5 + j * buttonlong - buttonlong + buttonmovedown, buttonlong - 1, buttonlong - 1, " ", PX_NULL);
			PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]);
			PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]);
			PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]);
			//生成结束cellbutton，下为根据colormode扫雷页面cellbutton的更改颜色
			if (colormode == 0)
			{
				; //白色就用原来的配色，所以不管
			}
			if (colormode == 1)
			{
				PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
				PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
			}
			if (colormode == 2)
			{
				PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
				PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
			}
			if (colormode == 3)
			{
				PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
				PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
			}
		}
	}
	start = clock();

	px_int buttonx;
	if (mode == 3)
	{
		buttonx = 730;
	}
	else
	{
		buttonx = 600;
	}
	PX_Object *returnwelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, buttonx, 400, 150, 40, "Return", PX_NULL);
	PX_ObjectRegisterEvent(returnwelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick2, PX_NULL);//初始化时的一个return按钮。
	return;
}

int failed = 0;

void Gamenow()
{
	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);

	///变换界面就删除原页面的object！（由Painterengine provide)///
	// printf("debug");
	int buttonlong, buttonmovedown;
	switch (mode)
	{
	case MODE_EASY:
		buttonlong = 50;
		buttonmovedown = 0;
		break;
	case MODE_MID:
		buttonlong = 31;
		buttonmovedown = 0;
		break;
	case MODE_HARD:
		buttonlong = 24;
		buttonmovedown = 50;
		break;
	} //根据大小生成buttoncell，buttonlong代表button的宽度，buttonmovedone是对困难模式时按钮向下移动（使得它不那么靠上）
	for (int i = 1; i <= Map->my; i++)
	{
		for (int j = 1; j <= Map->mx; j++)
		{
			cell[j][i].y = i;
			cell[j][i].x = j; // j行i列 x行y列

			if (Map->stage[j][i] == MARKED)
			{

				cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 1 + i * buttonlong - buttonlong, 5 + j * buttonlong - buttonlong + buttonmovedown, buttonlong - 1, buttonlong - 1, "?", PX_NULL);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]);
				if (colormode == 0)
				{
					; //白色就用原来的配色，所以不管
				}
				if (colormode == 1)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
				}
				if (colormode == 2)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
				}
				if (colormode == 3)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
				}
			}
			if (Map->stage[j][i] == FLAGED)
			{
				cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 1 + i * buttonlong - buttonlong, 5 + j * buttonlong - buttonlong + buttonmovedown, buttonlong - 1, buttonlong - 1, " ", PX_NULL);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]);
				if (mode == MODE_EASY)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &flag);
				}
				if (mode == MODE_MID)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &flag2);
				}
				if (mode == MODE_HARD)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &flag3);
				}
				//不同的mode对应flag的不同大小。
				if (colormode == 0)
				{
					; //白色就用原来的配色，所以不管
				}
				if (colormode == 1)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
				}
				if (colormode == 2)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
				}
				if (colormode == 3)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
				}
			}
			if (Map->stage[j][i] == UNCOVERED)
			{
				// printf("uncover%d %d\n", j, i);
				cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 1 + i * buttonlong - buttonlong, 5 + j * buttonlong - buttonlong + buttonmovedown, buttonlong - 1, buttonlong - 1, " ", PX_NULL);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]);
				if (colormode == 0)
				{
					; //白色就用原来的配色，所以不管
				}
				if (colormode == 1)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
					PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
				}
				if (colormode == 2)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
					PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
				}
				if (colormode == 3)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
					PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
				}
			}
			if (Map->stage[j][i] == COVERED)
			{
				// printf("cover%d %d\n", j, i);
				cellbutton[j][i] = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 1 + i * buttonlong - buttonlong, 5 + j * buttonlong - buttonlong + buttonmovedown, buttonlong - 1, buttonlong - 1, " ", PX_NULL);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_EXECUTE, Lclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORRDOWN, Rclickcell, &cell[j][i]);
				PX_ObjectRegisterEvent(cellbutton[j][i], PX_OBJECT_EVENT_CURSORMDOWN, Mclickcell, &cell[j][i]);
				if (opt_count(Map, j, i) == 0)
				{
					PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(32, 255, 255, 255));
					//标记为黑色按钮
				}
				else
				{
					int count = opt_count(Map, j, i);
					char text[2];
					sprintf(text, "%d", count);
					if (count)
						PX_Object_PushButtonSetText(cellbutton[j][i], text);

					if (colormode == 0)
					{
						; //白色就用原来的配色，所以不管
					}
					if (colormode == 1)
					{
						PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
						PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 238, 130, 238));
					}
					if (colormode == 2)
					{
						PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
						PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 106, 90, 205));
					}
					if (colormode == 3)
					{
						PX_Object_PushButtonSetBorderColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
						PX_Object_PushButtonSetCursorColor(cellbutton[j][i], PX_COLOR(255, 46, 139, 87));
					}
				}
			}
		}
	}
	//下为设置restart和open all 的按钮的语句
	px_int buttonx;
	if (mode == 3)
	{
		buttonx = 730;
	}
	else
	{
		buttonx = 600;
	}
	PX_Object *restartbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, buttonx, 350, 150, 40, "Restart", PX_NULL);
	PX_ObjectRegisterEvent(restartbutton, PX_OBJECT_EVENT_EXECUTE, restart, PX_NULL); //重开本局，相同难度模式下
	PX_Object *openallbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, buttonx, 300, 150, 40, "Open all", PX_NULL);
	PX_ObjectRegisterEvent(openallbutton, PX_OBJECT_EVENT_EXECUTE, openall, PX_NULL); //打开所有格子
	PX_Object *returnwelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, buttonx, 400, 150, 40, "Return", PX_NULL);
	PX_ObjectRegisterEvent(returnwelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick2, PX_NULL);//初始化时的一个return按钮。
	return;
}

void restart(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	Gameinit();
	return;
}

//////////////////////////////////////////////////////////////////////////////////
px_void *playagain(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	printf("\nRestarting...\n");
	Gameinit();
} //重新开始

px_void *towelcomeclick(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	printf("\nReturning....\n");
	WELCOME();
} 
px_void *towelcomeclick2(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	stop = clock();	
	printf("\nReturning....\n");
	WELCOME();
} 
//返回欢迎页2（增加了停止计时）

px_void *recordnameY(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	recordname_message = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxInputBox(recordname_message, "Enter your name please ", congratulation, PX_Object_MessageBoxGetInput(recordname_message), congratulation2, PX_NULL);

	return;
} //如果用户想输入名字就记录名字（因为消息对话框只能显示带有ok与cancel的界面，所以不能强制用户输入姓名）

px_void *congratulation(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{

	char *temptext = (char *)ptr;
	strcpy(name1, temptext);
	// printf("%s",*name1);
	sort(duration);
	PX_Object *winmessage3 = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertYesNo(winmessage3, "Do you want to paly again?", playagain, PX_NULL, towelcomeclick, PX_NULL);
} //为进入排行榜页面前三专门设置的祝福（免得太罗嗦，也免得输入名字的messagebox被吞掉）在recodename输入名字后调用本函数。
px_void *congratulation2(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{

	PX_Object *winmessage3 = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertYesNo(winmessage3, "Do you want to paly again?", playagain, PX_NULL, towelcomeclick, PX_NULL);
} //若用户点击取消（不输入名字）
//////////////////////////////////////////////////////////////////////////////////
void Gamewin() //游戏胜利
{
	stop = clock();								//暂停时间
	duration = (float)(stop - start) / CLK_TCK; //获取时间 以s为单位。
	printf("you win,TIME %f", duration);
	for (int i = 1; i <= Map->my; i++)
	{
		for (int j = 1; j <= Map->mx; j++)
		{
			PX_ObjectSetEnabled(cellbutton[j][i], PX_FALSE); //使得所有按钮无效，无法继续点击！
		}
	}

	if (is_topten(duration)) //如果能冲进前三，请求其输入名字，因为wjj还没有写函数，我就默认mode1的都进入了排行榜，会调用rank函数
	{
		PX_Object *winmessage = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
		const char *text[50];
		sprintf(text, "WOW!!!!!!!!!!\nYou Win!\nAND You're in the TOP TEN!!!\n It takes %.2f s\nMay I know your name?", duration);
		PX_Object_MessageBoxAlertYesNo(winmessage, text, recordnameY, PX_NULL, congratulation2, PX_NULL);
	}
	else
	{
		PX_Object *winmessage = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
		const char *text2[50];
		sprintf(text2, "Congradulation!\nYou Win!\nIt takes %.2f s\nDo you want to paly again?", duration);
		PX_Object_MessageBoxAlertYesNo(winmessage, text2, playagain, PX_NULL, towelcomeclick, PX_NULL);
	}
}

void Gamefail() //游戏失败
{
	stop = clock(); //暂停时间就不管了
	failed = 1;

	for (int i = 1; i <= Map->my; i++)
	{
		for (int j = 1; j <= Map->mx; j++)
		{
			if (Map->mineMap[j][i] == 1)
			{
				PX_Object_PushButtonSetText(cellbutton[j][i], " ");
				if (mode == 1)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &mine);
				}
				if (mode == 2)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &mine2);
				}
				if (mode == 3)
				{
					PX_Object_PushButtonSetShape(cellbutton[j][i], &mine3);
				}
				//根据mode调整雷的图片（shape）的大小
				PX_Object_PushButtonSetTextColor(cellbutton[j][i], PX_COLOR(255, 255, 0, 0));
			}
			PX_ObjectSetEnabled(cellbutton[j][i], PX_FALSE); //使得所有按钮无效，无法继续点击！
		}
	}
	printf("You lose");
	if (mode == 3)
	{
		failpic = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 720, 20, 200, 80, &failpicture);
	}
	else
	{
		failpic = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 570, 20, 200, 80, &failpicture);
	}
	PX_ObjectRegisterEvent(failpic, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	px_int buttonx;
	if (mode == 3)
	{
		buttonx = 730;
	}
	else
	{
		buttonx = 600;
	}

	PX_Object *returnwelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, buttonx, 400, 150, 40, "Return", PX_NULL);
	PX_ObjectRegisterEvent(returnwelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick, PX_NULL); //创建一个return按钮使得玩家可以返回主界面选择难度
																								   //为困难模式单独适配按钮的位置
}

//////////////////////////////////////////////////////////////////////////////////
//左中右键的控制&open all的控制函数
void Lclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e)) //检测鼠标操作是否在范围内
	{

		opt_t *pcell = (opt_t *)ptr;

		int temp;
		temp = fnOptLeftClick(pcell->x, pcell->y, Map);

		if (temp == BOOM)
		{
			Gamefail();
		} //是雷就失败
		else if (opt_is_scuess(*Map))
		{
			Gamewin();
		}
		else
		{
			Gamenow();
		}
	}
}

void Rclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{

		opt_t *pcell = (opt_t *)ptr;
		int temp;
		temp = fnOptRightClick(pcell->x, pcell->y, Map);
		if (opt_is_scuess(*Map))
		{
			Gamewin();
		}
		else
		{
			Gamenow();
		}
	}
}

void Mclickcell(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		opt_t *pcell = (opt_t *)ptr;
		int temp;
		temp = fnOptMidClick(pcell->x, pcell->y, Map);
		if (temp == BOOM)
		{
			Gamefail();
		}
		else if (opt_is_scuess(*Map))
		{
			Gamewin();
		}
		else
		{
			Gamenow();
		}
	}
}

void openall(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		opt_t *pcell = (opt_t *)ptr;
		int temp;
		temp = fnTotalFlag(Map);
		if (opt_is_scuess(*Map))
		{
			Gamewin();
		}
		else
		{

			Gamefail();
		}
	}
	return;
}

/////////////////////////////////////////////////////////////////////////
//不同的模式选择函数（点击模式按钮后调用本区域函数）
void ceasy(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		mode = 1;
		Gameinit();
	}
}

void cmid(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		mode = 2;
		Gameinit();
	}
}

void chard(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		mode = 3;
		Gameinit();
	}
}
/////////////////////////////////////////////////////
//下为模式选择界面（进入游戏时的模式选择）
void modechoose()
{

	//删除之前的按钮（如果有

	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);

	//重新创建根对象

	PX_Object *easymode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 150, 228, 64, "easy", PX_NULL);
	PX_ObjectRegisterEvent(easymode, PX_OBJECT_EVENT_EXECUTE, ceasy, &easymode);

	PX_Object *midmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 250, 228, 64, "middle", PX_NULL);
	PX_ObjectRegisterEvent(midmode, PX_OBJECT_EVENT_EXECUTE, cmid, &midmode);

	PX_Object *hardmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 350, 228, 64, "hard", PX_NULL);
	PX_ObjectRegisterEvent(hardmode, PX_OBJECT_EVENT_EXECUTE, chard, &hardmode);

	PX_Object *modechoose_title = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 290, 20, 300, 90, &modechoose_title_picture);
	PX_ObjectRegisterEvent(modechoose_title, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *modechoose_checkpic = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 290, 450, 300, 90, &modechoose_check);
	PX_ObjectRegisterEvent(modechoose_checkpic, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
}

/////////////////////////////////////////////////////
// rank 组件

void RANK()
{

	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);
	///变换界面就删除原页面的object！（由Painterengine provide)///

	PX_Object *towelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 40, 420, 160, 45, "Return", PX_NULL);
	PX_ObjectRegisterEvent(towelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick, &towelcomebutton);

	//第一二三名排版
	PX_Object *firstprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, -5, 90, 75, 75, &firstprizepicture);
	PX_ObjectRegisterEvent(firstprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *secondprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, -5, 190, 75, 75, &secondprizepicture);
	PX_ObjectRegisterEvent(secondprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *thirdprize = PX_Object_ImageCreate(&App.runtime.mp_resources, root, -5, 290, 75, 75, &thirdprizepicture);
	PX_ObjectRegisterEvent(thirdprize, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	PX_Object *divid_line = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 360, -35, 6, 550, &dividline);
	;
	PX_ObjectRegisterEvent(divid_line, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	PX_Object *rank4 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 370, 90, 75, 75, &rank4pic);
	PX_ObjectRegisterEvent(rank4, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *rank5 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 370, 190, 75, 75, &rank5pic);
	PX_ObjectRegisterEvent(rank5, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *rank6 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 370, 290, 75, 75, &rank6pic);
	PX_ObjectRegisterEvent(rank6, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	PX_Object *ranktitle = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 280, 0, 210, 75, &ranktitlepicture);
	PX_ObjectRegisterEvent(ranktitle, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *cheer = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 700, 415, 107, 107, &cheerpicture);
	;
	PX_ObjectRegisterEvent(cheer, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *ranknote2 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 190, 400, 500, 100, &ranknote2pic);
	PX_ObjectRegisterEvent(ranknote2, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	PX_Object *easyrank;
	PX_Object *midrank;
	PX_Object *hardrank;
	switch (RANKmode)
	{
	case 1:
		easyrank = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 750, -12, 100, 150, &easyrankpic);
		PX_ObjectRegisterEvent(easyrank, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
		break;
	case 2:
		midrank = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 750, -12, 100, 150, &midrankpic);
		PX_ObjectRegisterEvent(midrank, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
		break;
	case 3:
		hardrank = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 750, -12, 100, 150, &hardrankpic);
		PX_ObjectRegisterEvent(hardrank, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
		break;
	} //根据选择的排行版模式难度对应不同的提示图片（右侧标有简单困难的小旗帜）

	int valid_data = 0;
	typedef struct
	{
		char name[50];
		float time;
	} players;
	players player[11];
	if (RANKmode == 1)
	{
		FILE *fp1;
		fp1 = fopen("gamedata\\Rank_easydata.txt", "r");
		while (1)
		{
			if ((fscanf(fp1, "%s %f", player[valid_data + 1].name, &player[valid_data + 1].time)) == EOF)
			{
				break;
			}
			else
			{
				valid_data++;
			}
		}
	}
	if (RANKmode == 2)
	{
		FILE *fp2;
		fp2 = fopen("gamedata\\Rank_middata.txt", "r");
		while (1)
		{
			if ((fscanf(fp2, "%s %f", player[valid_data + 1].name, &player[valid_data + 1].time)) == EOF)
			{
				break;
			}
			else
			{
				valid_data++;
			}
		}
	}
	if (RANKmode == 3)
	{
		FILE *fp3;
		fp3 = fopen("gamedata\\Rank_harddata.txt", "r");
		while (1)
		{
			if ((fscanf(fp3, "%s %f", player[valid_data + 1].name, &player[valid_data + 1].time)) == EOF)
			{
				break;
			}
			else
			{
				valid_data++;
			}
		}
	}

	//下为根据有效数据的情况判断哪些位置还没有数据，以虚位以待的图片进行代替

	PX_Object *waiting_fordata1;
	PX_Object *waiting_fordata2;
	PX_Object *waiting_fordata3;
	PX_Object *waiting_fordata4;
	PX_Object *waiting_fordata5;
	PX_Object *waiting_fordata6;
	switch (valid_data)
	{
	case 0:
		waiting_fordata1 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 70, 100, 250, 50, &waiting_fordata);
		;
		PX_ObjectRegisterEvent(waiting_fordata1, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 1:
		waiting_fordata2 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 70, 200, 250, 50, &waiting_fordata);
		;
		PX_ObjectRegisterEvent(waiting_fordata2, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 2:
		waiting_fordata3 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 70, 310, 250, 50, &waiting_fordata);
		;
		PX_ObjectRegisterEvent(waiting_fordata3, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 3:
		waiting_fordata4 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 440, 100, 250, 50, &waiting_fordata);
		;
		PX_ObjectRegisterEvent(waiting_fordata4, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 4:
		waiting_fordata5 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 440, 200, 250, 50, &waiting_fordata);
		;
		PX_ObjectRegisterEvent(waiting_fordata5, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 5:
		waiting_fordata6 = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 440, 310, 250, 50, &waiting_fordata);
		PX_ObjectRegisterEvent(waiting_fordata6, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	default:
		break;
	}

	PX_Object *No1;
	char textno1[70];
	PX_Object *No2;
	char textno2[70];
	PX_Object *No3;
	char textno3[70];
	PX_Object *No4;
	char textno4[70];
	PX_Object *No5;
	char textno5[70];
	PX_Object *No6;
	char textno6[70];
	//根据有效数据的情况判断需要展示哪些文本框
	switch (valid_data)
	{
	case 7:
	case 8:
	case 9:
	case 10:
	case 11:
	case 12:
	case 13:
	case 6:
		sprintf(textno6, "NAME: %s \nTIME: %.3f s", player[6].name, player[6].time);
		No6 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 480, 210, 250, 250, textno6, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No6, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 5:
		sprintf(textno5, "NAME: %s \nTIME: %.3f s", player[5].name, player[5].time);
		No5 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 480, 110, 250, 250, textno5, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No5, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 4:
		sprintf(textno4, "NAME: %s \nTIME: %.3f s", player[4].name, player[4].time);
		No4 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 480, 10, 250, 250, textno4, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No4, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 3:
		sprintf(textno3, "NAME: %s \nTIME: %.3f s", player[3].name, player[3].time);
		No3 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 100, 210, 250, 250, textno3, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No3, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 2:
		sprintf(textno2, "NAME: %s \nTIME: %.3f s", player[2].name, player[2].time);
		No2 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 100, 110, 250, 250, textno2, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No2, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 1:
		sprintf(textno1, "NAME: %s \nTIME: %.3f s", player[1].name, player[1].time);
		No1 = PX_Object_LabelCreate(&App.runtime.mp_resources, root, 100, 10, 250, 250, textno1, PX_NULL, PX_COLOR(140, 255, 228, 196));
		PX_ObjectRegisterEvent(No1, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	case 0:
		break;
	}

	return;
}
/////////////////////////////////////////////////////////////////////////
//不同的模式选择函数（点击模式按钮后调用本区域函数）
void ceasy_rank(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		RANKmode = 1;
		RANK();
	}
}

void cmid_rank(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		RANKmode = 2;
		RANK();
	}
}

void chard_rank(PX_Object *pObject, PX_Object_Event e, px_void *ptr)
{
	if (PX_ObjectIsCursorInRegion(pObject, e))
	{
		RANKmode = 3;
		RANK();
	}
}
/////////////////////////////////////////////////////
//下为模式选择界面（进入排行时的模式选择）
void modechoose_rank()
{

	//删除之前的按钮（如果有

	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);

	//重新创建根对象

	PX_Object *easymode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 150, 228, 64, "easy", PX_NULL);
	PX_ObjectRegisterEvent(easymode, PX_OBJECT_EVENT_EXECUTE, ceasy_rank, &easymode);

	PX_Object *midmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 250, 228, 64, "middle", PX_NULL);
	PX_ObjectRegisterEvent(midmode, PX_OBJECT_EVENT_EXECUTE, cmid_rank, &midmode);

	PX_Object *hardmode = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 318, 350, 228, 64, "hard", PX_NULL);
	PX_ObjectRegisterEvent(hardmode, PX_OBJECT_EVENT_EXECUTE, chard_rank, &hardmode);
	PX_Object *modechoose_rank_title = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 290, 20, 290, 120, &modechoose_rank_title_picture);
	PX_ObjectRegisterEvent(modechoose_rank_title, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *modechoose_rank_trophy = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 40, 360, 290, 200, &modechoose_rank_trophypic);
	PX_ObjectRegisterEvent(modechoose_rank_trophy, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *modechoose_rank_note = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 150, 360, 590, 200, &modechoose_rank_notepic);
	PX_ObjectRegisterEvent(modechoose_rank_note, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
}

/////////////////////////////////////////////
// welcome 组件

px_void beginclick(PX_Object *pObject, PX_Object_Event e, px_void *ptr) //开始按钮的跳转
{
	printf("NOW begin!\n");
	modechoose();
}

px_void rankingclick(PX_Object *pObject, PX_Object_Event e, px_void *ptr) //排名按钮的跳转
{

	printf("Is ranking\t");
	modechoose_rank();
}

void WELCOME() //初始化函数
{
	///变换界面就删除原页面的object！（由Painterengine provide)///
	//删除之前的按钮（如果有

	//重新创建根对象
	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);
	///变换界面就删除原页面的object！///

	//初始化两个按钮
	PX_Object *beginbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 145, 400, 228, 64, "begin now", PX_NULL);
	PX_ObjectRegisterEvent(beginbutton, PX_OBJECT_EVENT_EXECUTE, beginclick, &beginbutton);

	PX_Object *rankingbutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 490, 400, 228, 64, "RANK", PX_NULL);
	PX_ObjectRegisterEvent(rankingbutton, PX_OBJECT_EVENT_EXECUTE, rankingclick, &rankingbutton);

	PX_Object *title = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 40, -225, 800, 800, &titlepicture);
	PX_ObjectRegisterEvent(title, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *potatoboom = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 2, 415, 110, 105, &potatoboompicture);
	PX_ObjectRegisterEvent(potatoboom, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	//这是MENU
	PX_Object_Menu_Item *pItem, *pItem1;
	PX_Object *menubutton = PX_Object_MenuCreate(&App.runtime.mp_ui, root, 10, 10, 200, PX_NULL);

	pItem = PX_Object_MenuAddItem(menubutton, PX_Object_MenuGetRootItem(menubutton), "_______< M e N u >_______", PX_NULL, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem, "[ H E L P ]", openhelp, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem, "[ Save to file ]", save_to_file, PX_NULL);
	pItem1 = PX_Object_MenuAddItem(menubutton, pItem, "[ Color ]", PX_NULL, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem1, "[ white ]", setcol_white, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem1, "[ pink ]", setcol_pink, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem1, "[ purple ]", setcol_purple, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem1, "[ green ]", setcol_green, PX_NULL);
	PX_Object_MenuAddItem(menubutton, pItem, "[ What is this?????? ]", opencolorfulegg, PX_NULL);

	//														     ↑可以用一个回调函数！！！！！！必须先创建一个px_void callback(px_void* userptr)函数,【函数名可以任意取】在函数里写东西
}
//////////////////////////////////////////////////////////////
//下为menu的返回函数
//下为颜色返回函数
void setcol_white(px_void *userptr)
{
	colormode = 0;
	PX_Object *setcolor = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertOk(setcolor, "The cells' color has changed to WHITE.It will take effect  in the game interface", PX_NULL, PX_NULL);
	return;
}
void setcol_pink(px_void *userptr)
{
	colormode = 1;
	PX_Object *setcolor = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertOk(setcolor, "The cells' color has changed to PINK.It will take effect only in the game interface", PX_NULL, PX_NULL);
}
void setcol_purple(px_void *userptr)
{
	colormode = 2;
	PX_Object *setcolor = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertOk(setcolor, "The cells' color has changed to PURPLE.It will take effect only in the game interface", PX_NULL, PX_NULL);
}
void setcol_green(px_void *userptr)
{
	colormode = 3;
	PX_Object *setcolor = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertOk(setcolor, "The cells' color has changed to GREEN.It will take effect only in the game interface", PX_NULL, PX_NULL);
}
//下为帮助界面
void openhelp(px_void *userptr)
{
	//重新创建根对象
	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);
	///变换界面就删除原页面的object！///
	PX_Object *towelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 370, 450, 128, 32, "Return", PX_NULL);
	PX_ObjectRegisterEvent(towelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick, &towelcomebutton);

	PX_Object *helptitle = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 330, 10, 210, 75, &help_title_picture);
	PX_ObjectRegisterEvent(helptitle, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *helptext = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 90, -100, 700, 700, &help_text_picture);
	PX_ObjectRegisterEvent(helptext, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);
	PX_Object *compasspic = PX_Object_ImageCreate(&App.runtime.mp_resources, root, 710, 345, 108, 108, &compass);
	; //第一的图片框（在rank里面
	PX_ObjectRegisterEvent(compasspic, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	return;
}
void opencolorfulegg(px_void *userptr)
{
	//重新创建根对象
	root = PX_ObjectCreate(&App.runtime.mp_ui, PX_NULL, 0, 0, 0, 0, 0, 0);
	///变换界面就删除原页面的object！///
	PX_Object *towelcomebutton = PX_Object_PushButtonCreate(&App.runtime.mp_ui, root, 370, 450, 128, 32, "Return", PX_NULL);
	PX_ObjectRegisterEvent(towelcomebutton, PX_OBJECT_EVENT_EXECUTE, towelcomeclick, &towelcomebutton);

	PX_Object *what_is_this = PX_Object_ImageCreate(&App.runtime.mp_resources, root, -60, -250, 1000, 1000, &what_is_this_pic);
	PX_ObjectRegisterEvent(what_is_this, PX_OBJECT_EVENT_ANY, PX_NULL, PX_NULL);

	return;
}

void save_to_file(px_void *userptr)
{
	PX_Object *save_to_file_message = PX_Object_MessageBoxCreate(&App.runtime.mp_ui, root, PX_NULL);
	PX_Object_MessageBoxAlertOk(save_to_file_message, "     We  automatically save it  when win.\nYou can check it in the gamedata folder.\nWe only record the top ten of each mode", PX_NULL, PX_NULL);
	return;
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//        以下为painterengine专门的函数请尽量不要更改！！！     //
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

px_bool PX_ApplicationInitialize(PX_Application *pApp, px_int screen_width, px_int screen_height) //初始化函数（px内部）
{
	SetConsoleTitle("MineSweeper_info");
	PX_ApplicationInitializeDefault(&pApp->runtime, screen_width, screen_height);
	//以下为欢迎页图片

	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &titlepicture, "assets\\titlepicture2.traw"); //加载图片！！
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &potatoboompicture, "assets\\potatoboom.traw");
	//注意文件地址！
	//以下为排行版页图片
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &firstprizepicture, "assets\\firstprize.traw"); //加载图片！！
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &secondprizepicture, "assets\\secondprize.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &thirdprizepicture, "assets\\thirdprize.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &ranktitlepicture, "assets\\ranktitlepicture.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &failpicture, "assets\\failpicture.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &cheerpicture, "assets\\cheerpicture.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &modechoose_title_picture, "assets\\modechoosetitle.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &modechoose_check, "assets\\modechoose_check.traw");

	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &help_title_picture, "assets\\helptitle.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &help_text_picture, "assets\\helptextpic.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &what_is_this_pic, "assets\\what_is_this_pic.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &modechoose_rank_title_picture, "assets\\modechoose_rankpicture.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &modechoose_rank_trophypic, "assets\\modechoose_rank_trophy.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &modechoose_rank_notepic, "assets\\ranknotepicture.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &ranknote2pic, "assets\\ranknote2pic.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &compass, "assets\\compass.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &easyrankpic, "assets\\easyrank.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &midrankpic, "assets\\midrank.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &hardrankpic, "assets\\hardrank.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &dividline, "assets\\dividline.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &waiting_fordata, "assets\\waiting_fordata.traw");

	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &rank4pic, "assets\\rank4.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &rank5pic, "assets\\rank5.traw");
	PX_LoadTextureFromFile(&pApp->runtime.mp_resources, &rank6pic, "assets\\rank6.traw");

	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &flag, "assets\\flagpicture.traw");
	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &flag2, "assets\\flag2picture.traw");
	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &flag3, "assets\\flag3picture.traw");
	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &mine, "assets\\minepicture.traw");
	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &mine2, "assets\\mine2picture.traw");
	PX_LoadShapeFromFile(&pApp->runtime.mp_resources, &mine3, "assets\\mine3picture.traw");

	WELCOME(); //直接前往welcome函数

	return PX_TRUE;
}

px_void PX_ApplicationUpdate(PX_Application *pApp, px_dword elpased)
{
}

px_void PX_ApplicationRender(PX_Application *pApp, px_dword elpased)
{
	px_surface *pRenderSurface = &pApp->runtime.RenderSurface;
	PX_RuntimeRenderClear(&pApp->runtime, PX_OBJECT_UI_DEFAULT_BACKGROUNDCOLOR);
	PX_ObjectRender(pRenderSurface, root, elpased);
}

px_void PX_ApplicationPostEvent(PX_Application *pApp, PX_Object_Event e)
{
	PX_ApplicationEventDefault(&pApp->runtime, e);
	PX_ObjectPostEvent(root, e);
}
